import numpy as np
import pandas as pd

input_example = [[-0.803556, 1.803556, 0.016222, 0.0, 0.0, 0.004444, 0.000444, 0.052444, 0.097556, 8450139.022222, 0.131081, 0.004413, 0.072321, 0.868919, 0.00305, 0.004159, 1209008640.0, 478536192.0, 31802.4, 32218.6, 22029476.5, 8450139.022222],
                 [-0.891333, 1.891333, 0.035778, 0.0, 0.0, 0.0, 0.0, 0.027556, 0.034444, 198337.422222, 0.076584, 0.003422, 0.047097, 0.923416, 0.005257, 0.003815, 598827520.0, 925864448.0, 2583.266667, 3061.8, 3030607.5, 198337.422222],
                 [float('nan'), float('nan'), float('nan'), float('nan'), float('nan'), float('nan'), float('nan'), float('nan'), float('nan'), 5677448.647111, 0.07524, 0.0034, 0.047145, 0.92476, 0.005285, 0.003765, 604049920.0, 923632128.0, float('nan'), float('nan'), 3011592.0, 5677448.647111],
                 [float('nan'), float('nan'), float('nan'), float('nan'), float('nan'), float('nan'), float('nan'), float('nan'), float('nan'), 16791924736.0, 0.146394, 0.006558, 0.087674, 0.853606, 0.003772, 0.004642, 1381130752.0, 1922301952.0, float('nan'), float('nan'), 22523937.0, 16791924736.0]]

output_example = [[-0.803556, 1.803556, 0.016222, 0.0, 0.0, 0.004444, 0.000444, 0.052444, 0.097556, 8450139.022222, 0.131081, 0.004413, 0.072321, 0.868919, 0.00305, 0.004159, 1209008640.0, 478536192.0, 31802.4, 32218.6, 22029476.5, 8450139.022222],
                 [-0.891333, 1.891333, 0.035778, 0.0, 0.0, 0.0, 0.0, 0.027556, 0.034444, 198337.422222, 0.076584, 0.003422, 0.047097, 0.923416, 0.005257, 0.003815, 598827520.0, 925864448.0, 2583.266667, 3061.8, 3030607.5, 198337.422222],
                 [0, 0, 0, 0, 0, 0, 0, 0, 0, 5677448.647111, 0.07524, 0.0034, 0.047145, 0.92476, 0.005285, 0.003765, 604049920.0, 923632128.0, 0, 0, 3011592.0, 5677448.647111],
                 [0, 0, 0, 0, 0, 0, 0, 0, 0, 16791924736.0, 0.146394, 0.006558, 0.087674, 0.853606, 0.003772, 0.004642, 1381130752.0, 1922301952.0, 0, 0, 22523937.0, 16791924736.0]]


def compare(o_e, o):
    assert isinstance(o_e, np.ndarray)
    assert isinstance(o, np.ndarray)
    if o_e.shape == o.shape:

        temp = o_e == o
        flag = True
        for row in temp:
            for col in row:
                flag = flag & col
        return flag
    else:
        return False


def ourpreprocess(temp_arr):
    no=temp_arr.shape[1]
    DSIZE=temp_arr.shape[0]
    for num in range(0,no):
        value=temp_arr[:,num]
        npArray=missing_value(value,DSIZE)
        temp_arr[:, num]=npArray
    return temp_arr


def missing_value(npArray, DSISE):
    missingValue = pd.notna(npArray)
    print(missingValue)

    # 存在缺失值，进行缺失值填充
    if (pd.isna(npArray).sum() > 0):
        npArray[np.isnan(npArray)] = 0.0

    return npArray


# 用例目的
print("该用例目的为：")
print("进行缺失值处理组件功能测试，在正常输入状态下能否获得预期结果")

# 子用例编号
print("子用例编号：")
print("missing_value_1")

print("****************************")
print("当前输入为：")
# 输出用例设置
print(input_example)
# 输出用例设置

print("")

print("****************************")
print("当前输出为:")
# 输出处理后数据

output = ourpreprocess(np.array(input_example))
print(output)
# 输出处理后数据

print("****************************")
print("是否正确:")
# 输出对比结果
# 需要写一个compare函数
if compare(np.array(output_example), output):
    print("输出与预定目标相符")
else:
    print("输出与预定目标不符")
# 输出对比结果

print("\n")

